package br.com.estevam.sisfin.components;

import org.apache.tapestry5.*;
import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.ioc.annotations.*;
import org.apache.tapestry5.BindingConstants;

import br.com.estevam.sisfin.data.Visit;

/**
 * Layout component for pages of application sisfin.
 */
@IncludeStylesheet("context:layout/layout.css")
public class Layout {
	
	@SessionState
	private Visit visit;
	
	/** The page title, for the <title> element and the <h1> element. */
	@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
	private String title;

	private String pageName;

	@Parameter(defaultPrefix = BindingConstants.LITERAL)
	private String sidebarTitle;

	@Parameter(defaultPrefix = BindingConstants.LITERAL)
	private Block sidebar;

	@Inject
	private ComponentResources resources;

	public String getClassForPageName() {
		return resources.getPageName().equalsIgnoreCase(pageName) ? "current_page_item" : null;
	}

	public String[] getPageNames() {
		if(visit.getId() == -1){
			return new String[] { "Index", "About", "Contact" };
		} else if (visit.getLogin().equalsIgnoreCase("admin")){
			return new String[] { "About", "Contact", "Menu", "Managers", "ModifyPassword","Logoff" };
		} else {
			return new String[] { "About", "Contact", "Menu", "ModifyPassword", "Logoff" };	
		}
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getPageName() {
		return pageName;
	}

	public void setPageName(String pageName) {
		this.pageName = pageName;
	}

	public String getSidebarTitle() {
		return sidebarTitle.toUpperCase();
	}

	public void setSidebarTitle(String sidebarTitle) {
		this.sidebarTitle = sidebarTitle.toUpperCase();
	}

	public Block getSidebar() {
		return sidebar;
	}

	public void setSidebar(Block sidebar) {
		this.sidebar = sidebar;
	}

	public ComponentResources getResources() {
		return resources;
	}

	public void setResources(ComponentResources resources) {
		this.resources = resources;
	}

	public Visit getVisit() {
		return visit;
	}

	public void setVisit(Visit visit) {
		this.visit = visit;
	}
	
}
